/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package card.core;

import frmwrk.core.APartyFactory;
import frmwrk.core.Organization;
import frmwrk.core.Party;
import frmwrk.core.Person;
import java.text.DateFormat;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;
import java.util.HashMap;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author akefeli
 */
public class PartyFactory implements APartyFactory {

    @Override
    public Party create(HashMap<String, String> params) {
        Party ret = null;
        
        String name = params.get("name");
        String street = params.get("street");
        String city = params.get("city");
        String state = params.get("state");
        String zip = params.get("zip");
        String email = params.get("email");
        
        if (params.get("type").equals("Organization")) {
                   
            int numberOfEmployees = Integer.parseInt(params.get("numberOfEmployees"));
            ret = new Organization(name, street, city, state, zip, email, numberOfEmployees);
            
        } else if (params.get("type").equals("Person")) {
            
            GregorianCalendar cal = null;
            try {
                DateFormat df = new SimpleDateFormat("dd MM yyyy");
                Date date = df.parse(params.get("birthdate"));
                cal = new GregorianCalendar();
                cal.setTime(date);
            } catch (ParseException ex) {
                Logger.getLogger(PartyFactory.class.getName()).log(Level.SEVERE, null, ex);
            }

            ret = new Person(name, street, city, state, zip, email, cal);
        } else {
            System.out.println("Wrong type for party!!!");
        }
        
        return ret;
    }
}
